package com.molyfun.parents.activity.report;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.github.mikephil.charting.charts.PieChart;
import com.molyfun.parents.R;
import com.molyfun.parents.fragment.BaseFragment;
import com.molyfun.parents.utils.Const;
import com.molyfun.parents.utils.MPChartHelper;
import com.molyfun.parents.utils.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2017/12/14 0014.
 */

public class GeneralDescripeFragment extends BaseFragment {

    @InjectView(R.id.tv_strtime)
    TextView tv_time;

    @InjectView(R.id.totle_course)
    TextView totle_course;

    @InjectView(R.id.tv_mySelfe)
    TextView tv_mySelfe;

    @InjectView(R.id.tv_sistisis)
    TextView tv_sistisis;
    @InjectView(R.id.pieChart)
    PieChart pieChart;

    private Map<String, Float> pieValues;
    private String mReportId;

    public static GeneralDescripeFragment newInstance(int category, String strTime, String reportId, String courseTotle, String courseAssis, String courseFinishi, String uncompletedNum) {
        GeneralDescripeFragment genetralDesoFragment = new GeneralDescripeFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("category", category);
        bundle.putString(Const.FLAG_TIME_INTERVAL, strTime);
        bundle.putString(Const.REPORT_ID, reportId);
        bundle.putString("courseTotel", courseTotle);
        bundle.putString("courseAssis", courseAssis);
        bundle.putString("courseFinish", courseFinishi);//独立完成
        bundle.putString("uncompletedNum", uncompletedNum);
        genetralDesoFragment.setArguments(bundle);
        return genetralDesoFragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_general_des, null);
        ButterKnife.inject(this, view);
        initView();

        return view;
    }

    private void initView() {
        String timeInterval = getArguments().getString(Const.FLAG_TIME_INTERVAL);
        mReportId = getArguments().getString(Const.REPORT_ID);
        mReportId = getArguments().getString(Const.REPORT_ID);
        String mCourseTotel = getArguments().getString("courseTotel");
        String mCourseMyselfFinish = getArguments().getString("courseFinish");
        String mCourseAssisNum = getArguments().getString("courseAssis");
        String mUncompletedNum = getArguments().getString("uncompletedNum");
        totle_course.setText("课程总数: " + mCourseTotel + "个");
        tv_mySelfe.setText("独立完成: " + mCourseMyselfFinish + "个");
        tv_sistisis.setText("辅助完成: " + mCourseAssisNum + "个");
        if (timeInterval != null && !TextUtils.isEmpty(timeInterval)) {
            tv_time.setText(timeInterval + "");
        }
        if (mUncompletedNum != null && mCourseAssisNum != null && mCourseMyselfFinish != null) {
            initData(mUncompletedNum, mCourseAssisNum, mCourseMyselfFinish);
            MPChartHelper.setPieChart(pieChart, pieValues, "", true);
        } else {
            return;
        }
    }

    private void initData(String mUncompletedNum, String mCourseAssisNum, String mCourseMyselfFinish) {
        Float uncompletedNum = StringUtils.convertToFloat(mUncompletedNum, 0);
        Float courseAssisNum = StringUtils.convertToFloat(mCourseAssisNum, 0);
        Float courseMyselfCompeNum = StringUtils.convertToFloat(mCourseMyselfFinish, 0);
        pieValues = new LinkedHashMap<>();
//        pieValues.put("未完成:"+Integer.valueOf(mUncompletedNum)+"个", uncompletedNum);
//        pieValues.put("辅助完成:"+Integer.valueOf(mCourseAssisNum)+"个", courseAssisNum);
//        pieValues.put("独立完成:"+Integer.valueOf(mCourseMyselfFinish)+"个", courseMyselfCompeNum);
        pieValues.put("未完成", uncompletedNum);
        pieValues.put("辅助完成", courseAssisNum);
        pieValues.put("独立完成", courseMyselfCompeNum);

    }
}
